﻿package cgs.server.logging.requests
{
    import cgs.server.logging.*;
    import com.adobe.serialization.json.*;
    import com.hurlant.util.*;
    import flash.net.*;

    public class ServerRequest extends CallbackRequest implements IServerRequest
    {
        public var _generalURL:String;
        public var _method:String;
        public var _responseClass:Class;
        public var data:Object;
        public var params:Object;
        public var _dataFormat:String;
        protected var _extraData:Object;
        protected var _urlType:int = 1;
        protected var _gameServerData:GameServerData;
        public static const LOGGING_URL:int = 1;
        public static const AB_TESTING_URL:int = 2;
        public static const GENERAL_URL:int = 3;

        public function ServerRequest(param1:String, param2:Function, param3:Object, param4:Object = null, param5 = null, param6:Class = null, param7:String = "text", param8:String = null, param9:GameServerData = null)
        {
            super(param2);
            this._method = param1 != null ? (param1) : ("");
            this._responseClass = param6;
            this.data = param3;
            this.params = param4;
            this._dataFormat = param7;
            this._extraData = param5;
            this._generalURL = param8;
            this._gameServerData = param9 == null ? (GameServerData.instance) : (param9);
            return;
        }// end function

        public function get responseClass() : Class
        {
            return this._responseClass;
        }// end function

        public function get method() : String
        {
            return this._method;
        }// end function

        public function set urlType(param1:int) : void
        {
            this._urlType = param1;
            return;
        }// end function

        public function get isPOST() : Boolean
        {
            return false;
        }// end function

        public function get isGET() : Boolean
        {
            return true;
        }// end function

        public function get dataFormat() : String
        {
            return this._dataFormat;
        }// end function

        public function get extraData()
        {
            return this._extraData;
        }// end function

        public function get baseURL() : String
        {
            var _loc_1:String = "";
            if (this._urlType == LOGGING_URL)
            {
                _loc_1 = this._gameServerData.serverURL;
            }
            else if (this._urlType == AB_TESTING_URL)
            {
                _loc_1 = this._gameServerData.abTestingURL;
            }
            else if (this._urlType == GENERAL_URL)
            {
                _loc_1 = this._generalURL;
            }
            return _loc_1 + this._method + "?";
        }// end function

        public function get urlVariables() : URLVariables
        {
            var _loc_3:JSONEncoder = null;
            var _loc_4:String = null;
            var _loc_5:String = null;
            var _loc_1:* = new URLVariables();
            var _loc_2:String = "";
            if (this.data != null)
            {
                _loc_3 = new JSONEncoder(this.data);
                _loc_2 = _loc_3.getString();
                _loc_4 = _loc_2;
                if (this._gameServerData.dataEncoding == GameServerData.BASE_64_ENCODING)
                {
                    _loc_4 = Base64.encode(_loc_2);
                }
                _loc_1.data = _loc_4;
            }
            if (this._gameServerData.skeyHashVersion == GameServerData.DATA_SKEY_HASH)
            {
                _loc_1.skey = this._gameServerData.createSkeyHash(_loc_2);
            }
            _loc_1.de = this._gameServerData.dataEncoding;
            if (this.params != null)
            {
                for (_loc_5 in this.params)
                {
                    
                    _loc_1.param = this.params[_loc_5];
                }
            }
            if (this._gameServerData.useDevelopmentServer)
            {
                _loc_1.latency = CGSServerConstants.serverLatency;
            }
            _loc_1.noCache = CGSServer.getTimeStamp();
            return _loc_1;
        }// end function

        public function get url() : String
        {
            var _loc_4:JSONEncoder = null;
            var _loc_5:String = null;
            var _loc_6:String = null;
            var _loc_1:* = this.baseURL;
            var _loc_2:Boolean = false;
            var _loc_3:String = "";
            if (this.data != null)
            {
                _loc_4 = new JSONEncoder(this.data);
                _loc_3 = _loc_4.getString();
                _loc_5 = _loc_3;
                if (this._gameServerData.dataEncoding == GameServerData.BASE_64_ENCODING)
                {
                    _loc_5 = Base64.encode(_loc_3);
                }
                _loc_1 = _loc_1 + ("data=" + _loc_5);
                _loc_2 = true;
            }
            if (this._gameServerData.skeyHashVersion == GameServerData.DATA_SKEY_HASH)
            {
                if (_loc_2)
                {
                    _loc_1 = _loc_1 + "&";
                }
                _loc_1 = _loc_1 + ("skey=" + this._gameServerData.createSkeyHash(_loc_3));
                _loc_2 = true;
            }
            if (_loc_2)
            {
                _loc_1 = _loc_1 + "&";
            }
            _loc_1 = _loc_1 + ("de=" + this._gameServerData.dataEncoding);
            _loc_2 = true;
            if (this.params != null)
            {
                for (_loc_6 in this.params)
                {
                    
                    _loc_1 = _loc_1 + ("&" + _loc_6 + "=" + this.params[_loc_6]);
                }
            }
            if (this._gameServerData.useDevelopmentServer)
            {
                _loc_1 = _loc_1 + ("&latency=" + CGSServerConstants.serverLatency);
            }
            _loc_1 = _loc_1 + ("&noCache=" + CGSServer.getTimeStamp());
            return _loc_1;
        }// end function

    }
}
